<div class="layuimini-container layuimini-page-anim">
	<div class="layuimini-main">

		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<div style="margin: 10px 10px 10px 10px">
				<form class="layui-form layui-form-pane" action="">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label ">设备编号</label>
							<div class="layui-input-block">
								<input type="number" name="id" maxLength='12'  value=""  class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label ">设备类型</label>
							<div class="layui-input-block">
								<select id="type" name="type" lay-filter="st"
									item_url="/item_lib/dev_type.json" item-filter="0,1">
									<option value="">全部</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
								<label class="layui-form-label ">蓝牙MAC</label>
								<div class="layui-input-inline">
									<input type="text" name="bleId" maxLength='16' value=""
										class="layui-input">
								</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">状态</label>
							<div class="layui-input-inline">
								<select id="status" name="status"  lay-filter="st"
									item_url="/item_lib/dev_status.json">
									<option value="">全部</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">自编号</label>
							<div class="layui-input-inline">
									<input type="text" name="position" maxLength='16' value=""
										class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<button type="submit" class="layui-btn layui-btn-primary"
								lay-submit lay-filter="data-search-btn">
								<i class="layui-icon"></i>搜 索
							</button>
						</div>
					</div>
				</form>
			</div>
		</fieldset>

		<table class="layui-table" id="currentTableId"
			lay-filter="currentTableFilter">
		</table>
		<script type="text/html" id="switchStatus">
			  <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="正常|锁定" lay-filter="svrStatus" {{ d.status == 1 ? 'checked' : '' }}>
		</script>

	</div>
</div>


<script>
	
    layui.use(['form', 'table','miniPage','element','common'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
             layarea = layui.layarea,
            miniPage = layui.miniPage;
        
        table.render({
        	elem: '#currentTableId',
        	url: '/device/', 
        	//where:{type:-1},
        	toolbar: '<div class="layui-btn-container"></div>', 
        	defaultToolbar: [ 'exports', 'print'], 
			limits: [20, 30, 50, 100], 
			limit: 20,	
			even:true,
			skin: 'row',
			page: true,
              cols: [[
                {type: 'radio', width: 30, title: '选择'},
                {field: 'id', width: 120,  sort: true, title: 'ID'}, 
                {field:'type', minWidth:100, templet:function(d){return layui.common.castValueLable('/item_lib/dev_type.json' ,d.type);}, title: '设备类别'},
                {field:'position', minWidth:200, sort: false, title: '自编号', sort: false},
                {field:'model', minWidth:200, title: '型号'},
                {field:'batch', minWidth:200, title: '批次'},
               	{fixed: 'right', field: 'status', width: 100, title: '状态', templet: '#switchStatus', unresize: true, title: '状态'}
              ]]
        });
		
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                },
                 where:  data.field
            	});
            return false;
        });
	  
  		//监听锁定操作
  		form.on('switch(svrStatus)', function(obj){
  			var svrSt=-1
  			var svrId=this.value
  			if (obj.elem.checked)
  				svrSt=1
  			layui.common.ajaxUpdate("/device/status/"+svrId+"/"+svrSt)
  		});

    	//初始化选择框    
		layui.common.initSelect();

    });
</script>